<?php
/**
 * 客户联系人
 */
require_once("../global.inc.php");
require_once(BasePath . '/classes/libraries/fileoperate.class.php');

class SysDoingFlowClass extends SystemFrameWork{
	/**
	 * 客户联系人对象
	 *
	 * @var obj
	 */
	var $obj_customer;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $obj_validate;
	/**
	 * 分页对象
	 *
	 * @var obj
	 */
	var $obj_page;
	
	/**
	 * 项目执行方案操作对象
	 *
	 * @var obj
	 */
	var $obj_project_scheme;
	
	/**
	 * 稿件规划信息操作对象
	 *
	 * @var obj
	 */
	var $obj_gaojian;
	
	/**
	 * 媒介执行规划信息操作对象
	 *
	 * @var unknown_type
	 */
	var $obj_meijie_exe;
	
	/**
	 * 媒介执行规划详情操作对象
	 *
	 * @var unknown_type
	 */
	var $obj_meijie_exe_detail;
	
	function main(){
	    /**
		 * 创建验证对象
		 */
		if (!is_object($this->obj_validate)){
			require_once("commonvalidate.class.php");
			$this->obj_validate = new CommonValidate();
		}
		/**
		 * 初始化分页类
		 */
		if (!is_object($this->obj_page)){
			require_once("commonpage.class.php");
			$this->obj_page = new CommonPage();
		}
		
		if (!is_object($this->obj_project_scheme))
		{
			require_once("projectscheme.class.php");
			$this->obj_project_scheme = new ProjectSchemeClass();
		}
		
		if (!is_object($this->obj_gaojian))
		{
			require_once("gaojian.class.php");
			$this->obj_gaojian = new GaojianClass();
		}
		
		if (!is_object($this->obj_meijie_exe))
		{
			require_once("meijie_exe.class.php");
			$this->obj_meijie_exe = new MeijieExeClass();
		}
		
		if (!is_object($this->obj_meijie_exe_detail))
		{
			require_once('meijie_exe_detail.class.php');
			$this->obj_meijie_exe_detail = new MeijieExeDetailClass();
		}
		switch($this->_input['action']){
			case "zhixing":
			    $this->_zhixing();
			    break;
			case "zhixing_view":
			    $this->_zhixing_view();
			    break;
			case "save_zhixing":
				$this->_save_zhixing();
				break;
			case "download_fangan":
				$this->_download_fangan();
				break;
			case "del_fangan":
				$this->_del_fangan();
				break;
			case "gaojian":
			    $this->_gaojian();
			    break;
			case "save_gaojian":
				$this->_save_gaojian();
				break;
			case "gaojian_view":
			    $this->_gaojian_view();
			    break;
			case "meijie":
			    $this->_meijie();
			    break;
			case 'save_meijie':
				$this->_save_meijie();
				break;
			case "meijie_view":
			    $this->_meijie_view();
			    break;
			case "zhichu":
			    $this->_zhichu();
			    break;
			case "zhichu_view":
			    $this->_zhichu_view();
			    break;
			case "fapiao":
			    $this->_fapiao();
			    break;
			case "fapiao_view":
			    $this->_fapiao_view();
			    break;
			case "huikuan":
			    $this->_huikuan();
			    break;
			case "huikuan_view":
			    $this->_huikuan_view();
			    break;
	       default :
		}
	}
	
	public function _zhixing()
	{
		$this->_input['project_id'] = 1;
		$fangan = $this->obj_project_scheme->getSchemeByPid($this->_input['project_id']);

		$this->output('fangan', $fangan);
		$this->output('project_id', 1);
	    $this->showpage('doing_flow.zhixing');
	}
	
	public function _zhixing_view()
	{
	    $this->showpage('doing_flow.zhixing_view');
	}
	
	public function _save_zhixing()
	{
		$result = FileOperate::upload_file($_FILES['fangan']);
		if ($result['code'] === 'errer')
		{
			$this->redirectPath('error','',$result['msg'],1);
		}
		$value_array = array();
		$value_array['title']       = $this->_input['title'];
		$value_array['file_name']   = $result['safe_file_name'];
		$value_array['e_id']        = $_SESSION['s_admin']['id'];
		$value_array['create_time'] = time();
		$value_array['p_id']        = $this->_input['project_id'];
		$value_array['status']      = 1;
		$res = $this->obj_project_scheme->addScheme($value_array);
		if ($res != true)
		{
			$this->redirectPath('error','','提交失败',1);
		}
		else
		{
			$this->redirectPath('error','doing_flow.manage.php?action=zhixing&project_id=' . $this->_input['project_id'],'提交成功',1);
		}
	}

	public function _download_fangan()
	{
		$fangan = $this->obj_project_scheme->getSchemeById($this->_input['fangan_id']);
		
		if (empty($fangan) === TRUE)
		{
			$this->redirectPath('error','','下载失败',1);
		}
		
		$file_path = BasePath . '/project/fangan/' . $fangan['file_name'];
		
		if (!file_exists($file_path))
		{
			$this->redirectPath('error','','下载失败,文件不存在。',1);
		}

		return FileOperate::download($fangan['file_name'], 'fangan');
	}
	
	public function _del_fangan()
	{
		$rs = $this->obj_project_scheme->getSchemeById($this->_input['id']);
		
		FileOperate::del_file($rs['file_name'], 'fangan');
		$result = $this->obj_project_scheme->delScheme($this->_input['id']);
		if (!$result)
		{
			$this->redirectPath('error', 'doing_flow.manage.php?action=zhixing', '删除失败', 1);
		}
		
		$this->redirectPath('error', 'doing_flow.manage.php?action=zhixing', '删除成功，请重新上传执行方案', 1);
	}

	public function _gaojian()
	{
		$this->_input['project_id'] = 1;
		$project_id = $this->_input['project_id'];
		
		$this->output('project_id', $project_id);
	    $this->showpage('doing_flow.gaojian');
	}
	
	public function _save_gaojian()
	{
		var_dump($this->_input);
	}

	public function _gaojian_view()
	{
	    $this->showpage('doing_flow.gaojian_view');
	}
	
	public function _meijie()
	{
	    $this->showpage('doing_flow.meijie');
	}
	
	public function _save_meijie()
	{
		
	}
	
	public function _meijie_view()
	{
	    $this->showpage('doing_flow.meijie_view');
	}
	
	public function _zhichu()
	{
	    $this->showpage('doing_flow.zhichu');
	}
	
	public function _zhichu_view()
	{
	    $this->showpage('doing_flow.zhichu_view');
	}
	
	public function _fapiao()
	{
	    $this->showpage('doing_flow.fapiao');
	}
	
	public function _fapiao_view()
	{
	    $this->showpage('doing_flow.fapiao_view');
	}
	
	public function _huikuan()
	{
	    $this->showpage('doing_flow.huikuan');
	}
	
	public function _huikuan_view()
	{
	    $this->showpage('doing_flow.huikuan_view');
	}
}

$doing_flow = new SysDoingFlowClass();
$doing_flow->main();
unset($doing_flow);
?>